var { ReturnModel } = require('../libs/resmodel');
var { inviterhistorySave, inviterhistoryAudit, inviterhistoryList, inviterApply, inviterhistoryQueryOne,inviterSaveInfo,getInviterListBack } = require('../services/inviterhistory');

/**
* 申请成为推荐人
* @api {post} /inviterhistory/save 申请成为推荐人
* @apiDescription 申请成为推荐人
* @apiName save
* @apiParam (参数) {String} pcode 申请人pcode
* @apiSampleRequest /inviterhistory/save
* @apiGroup inviterhistory-申请推荐人
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "pcode": "290464549598", // 申请人pcode
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "msg": "保存成功",
*      "code": 0
*   }
*/
async function save(req, res) {
    let result = await inviterhistorySave(req.body);
    res.json(new ReturnModel(result));
}
/**
* 获取推荐人申请列表
* @api {post} /inviterhistory/list 获取推荐人申请列表
* @apiDescription 获取推荐人申请列表
* @apiName list
* @apiParam (参数) {String} ispass 按审批状态筛选，不传查所有（0：未审核， 1：通过 9：不通过）
* @apiParam (参数) {String} name 按名称筛选，不传查所有
* @apiParam (参数) {Number} pagenum 查询第几页(默认第1页)
* @apiParam (参数) {Number} pagesize 每页显示条数(默认10条)
* @apiSampleRequest /inviterhistory/list
* @apiGroup inviterhistory-申请推荐人
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "ispass": 0, 
*       "name": "科技",
*       "pagenum": 1,  // 查询第几页
*       "pagesize": 10,  // 每页显示条数 
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "data": {
*         "list":[{
*       "id": "12", // 记录id
*       "pcode": "290464549598", // 申请人pcode
*       "auditcode": "249485919615", // 审批人code
*       "nickname": "会飞的鱼", // 用户昵称
*       "name": "张三", // 用户姓名
*       "name": "张三", // 用户姓名
*       "isconfirm": 1, // 是否确认，0：未确认， 1：已确认 9：已拒绝
*       "ispass": 1, // 是否通过，0：未审核， 1：通过 9：不通过
*       "commit": "通过", // 审批意见
*       "yusercount": 12, // 邀请用户数
*       "yusercount_online": 2, // 已发布用户数
*       "yvitercount": 4, // 邀请推荐人数
*       "yvitercount_online": 2, // 成为推荐人数
*       "createtime": "2022-04-02 15:23:22", // 申请时间
*       "audittime": "2022-04-02 15:23:22", // 审批时间
*       }],
*        "total": 200,//总条数
*        "pagecount": 20,//总页数
*        }
*      "msg": "获取成功",
*      "code": 0
*   }
*/
async function list(req, res) {
    let result = await inviterhistoryList(req.body, req.headers.userrole);
    res.json(new ReturnModel(result));
}
/**
* 获取推荐人详情
* @api {post} /inviterhistory/QueryOne 获取推荐人详情
* @apiDescription 获取推荐人详情
* @apiName QueryOne
* @apiParam (参数) {String} id 
* @apiSampleRequest /inviterhistory/QueryOne
* @apiGroup inviterhistory-申请推荐人
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "id": 23
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "data": {
*       "id": "12", // 记录id
*       "nickname": "用户昵称", 
*       "name": "用户姓名",
*       "phone": "131xxxxxx", // 用户手机号
*       "wechat_code": "aasda", // 微信号
*       "email": "1231231@163.com", // 邮箱
*       "idcard": "身份证号", 
*       "grender": "性别", 
*       "marital_status": "婚姻状态", 
*       "jiguan": "籍贯", 
*       "education": "学历", 
*       "university": "毕业院校", 
*       "occupation": "职业", 
*       "company": "单位", 
*       "position": "职位", 
*       "business": "企业状况", 
*       "lovestory": "爱心事例", 
*       "workresume": "工作简历", 
*       "description": "自我描述", 
*       "inviter_name": "推荐人姓名"
*        }
*      "msg": "获取成功",
*      "code": 0
*   }
*/
async function QueryOne(req, res) {
    let result = await inviterhistoryQueryOne(req.body);
    res.json(new ReturnModel(result));
}

/**
* 处理推荐人申请
* @api {post} /inviterhistory/audit 处理推荐人申请
* @apiDescription 管理员审核通过之后，用户升级为推荐人，页面加载申请人权限页面；审核不通过，用户需要重新提交申请
* @apiName audit
* @apiParam (参数) {String} id 申请记录id
* @apiParam (参数) {Number} ispass 是否通过，1：通过，9: 不通过
* @apiParam (参数) {String} commit 审批意见
* @apiSampleRequest /inviterhistory/audit
* @apiGroup inviterhistory-申请推荐人
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "id": "1",
*       "ispass": 1,
*       "commit": "通过"
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "msg": "处理成功",
*      "code": 0
*   }
*/
async function audit(req, res) {
    let result = await inviterhistoryAudit(req.body);
    res.json(new ReturnModel(result));
}
/**
* 申请推荐人-公众号
* @api {post} /inviterhistory/inviterapply 申请推荐人-公众号
* @apiDescription 申请推荐人-公众号
* @apiName inviterapply
* @apiParam (参数) {String} nickname 昵称
* @apiParam (参数) {String} name 真实姓名
* @apiParam (参数) {String} phone 手机号
* @apiParam (参数) {String} wechat_code 微信号
* @apiParam (参数) {String} email 邮箱
* @apiParam (参数) {String} idcard 身份证号
* @apiParam (参数) {String} grender 性别
* @apiParam (参数) {String} marital_status 婚姻状态  枚举：未婚、离异无孩、离异带孩、离异不带孩、丧偶
* @apiParam (参数) {String} jiguan 籍贯，如：湖南长沙
* @apiParam (参数) {String} education 学历
* @apiParam (参数) {String} university 手毕业学校
* @apiParam (参数) {String} occupation 职业
* @apiParam (参数) {String} company 单位
* @apiParam (参数) {String} position 职位
* @apiParam (参数) {String} business 企业状况
* @apiParam (参数) {String} lovestory 爱心事例
* @apiParam (参数) {String} workresume 工作简历
* @apiParam (参数) {String} description 自我描述
* @apiParam (参数) {String} inviter_name 推荐人姓名
* @apiParam (参数) {String} synopsis 推荐人简介
* @apiSampleRequest /inviterhistory/inviterapply
* @apiGroup API-公众号
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "name": "张三",
*       "grender": "男",
*       "idcard": "441123123123123123",
*       "marital_status": "已婚",
*       "province_town": "湖南省",
*       "city_town": "株洲市",
*       "area_town": "攸县",
*       "education": "本科",
*       "university": "xx大学",
*       "phone": "1310000000",
*       "wechat_code": "1310000000",
*       "email": "xxxx@163.com",
*       "occupation": "退休人员",
*       "company": "xxx公司",
*       "position": "总经理",
*       "job": "高级",
*       "resume": "http://redspider.oss-cn-shenzhen.aliyuncs.com/redspider_v1.0/个人简历.docx",
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "msg": "您的申请已提交平台，等待管理员审核",
*      "code": 0
*   }
*/
async function inviterapply(req, res) {
    let result = await inviterApply(req.body);
    res.json(new ReturnModel(result));
}

/**
* 保存推荐人信息
* @api {post} /inviterhistory/saveinfo 保存推荐人信息
* @apiDescription 保存推荐人信息
* @apiName saveinfo
* @apiParam (参数) {String} nickname 昵称
* @apiParam (参数) {String} name 真实姓名
* @apiParam (参数) {String} phone 手机号
* @apiParam (参数) {String} wechat_code 微信号
* @apiParam (参数) {String} email 邮箱
* @apiParam (参数) {String} idcard 身份证号
* @apiParam (参数) {String} grender 性别
* @apiParam (参数) {String} marital_status 婚姻状态  枚举：未婚、离异无孩、离异带孩、离异不带孩、丧偶
* @apiParam (参数) {String} jiguan 籍贯，如：湖南长沙
* @apiParam (参数) {String} education 学历
* @apiParam (参数) {String} university 手毕业学校
* @apiParam (参数) {String} occupation 职业
* @apiParam (参数) {String} company 单位
* @apiParam (参数) {String} position 职位
* @apiParam (参数) {String} business 企业状况
* @apiParam (参数) {String} lovestory 爱心事例
* @apiParam (参数) {String} workresume 工作简历
* @apiParam (参数) {String} description 个人简介
* @apiParam (参数) {String} inviter_name 推荐人姓名
* @apiSampleRequest /inviterhistory/saveinfo
* @apiGroup inviterhistory-申请推荐人
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
*     {
*       "id": 24, 
*       "name": "文祖良", 
*       "grender": "男", 
*       "description": "文祖良，男，65年，深圳退休公务员，湖南攸县人，解放军国防科技大学硕士。从军19年，公务员13年，长期热心助人，成功撮合多对，是红豆家缘相亲平台发起人之一", 
*     }
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "msg": "保存成功",
*      "code": 0
*   }
*/
async function saveinfo(req, res) {
    let result = await inviterSaveInfo(req.body);
    res.json(result);
}
/**
* 获取推荐人列表-后台
* @api {get} /inviterhistory/getinviterlistback 获取推荐人列表-后台
* @apiDescription 获取推荐人列表-后台
* @apiName getinviterlistback
* @apiSampleRequest /inviterhistory/getinviterlistback
* @apiGroup inviterhistory-申请推荐人
* @apiVersion 1.0.0
* @apiParamExample {json} Request-Example:
* @apiSuccessExample {json} Success-Response:
*   HTTP/1.1 200 OK
*   {
*      "data": ["张三"、"李四"],
*      "code": 0
*   }
*/
async function getinviterlistback(req, res) {
    let result = await getInviterListBack();
    res.json(result);
}
module.exports = function (app) {
    let base_url = '/api/inviterhistory';

    app.post(base_url+'/save', save);
    app.post(base_url+'/list', list);
    app.post(base_url+'/audit', audit);
    app.post(base_url+'/inviterApply', inviterapply);
    app.post(base_url+'/QueryOne', QueryOne);
    app.post(base_url+'/saveinfo', saveinfo);
}
